package cc.booku.owlbox.UnNavDataPage;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;

import androidx.appcompat.app.AppCompatActivity;

import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.bumptech.glide.Glide;
import com.timmy.tdialog.TDialog;

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import cc.booku.owlbox.ArtDesign.SystemUtil;
import cc.booku.owlbox.FileOperations.FileoOperations;
import cc.booku.owlbox.R;
import cc.booku.owlbox.RsaUtil.Decrypt;
import cc.booku.owlbox.UnSearchPage.SearchActivity;
import cc.booku.owlbox.UnSearchPage.SearchListActivity;
import cc.booku.owlbox.VideoPlayer.FullScreen.FullScreenActivity;
import cc.booku.owlbox.VideoPlayer.PlayerActivity;
import cc.booku.owlbox.VideoPlayer.VideoPlayerActivity;
import cn.bingoogolapple.bgabanner.BGABanner;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

public class NavDataActivity extends AppCompatActivity {


    //private Toolbar Toolbar;
    private TextView Fromfileurl, tv_changebatch, tv_customize, tv_search, tv_customize2, tv_unnum, tv_warn;
    private ImageView iv_back;
    private TDialog tDialog;
    private NetworkImageView iv_billboard, iv_billboard2;
    private GridView collectionstationGridview, CustomizeGridview, gv_customizetoday, gv_customizeea;
    private HorizontalListView hl_navtab;

    private String ProfilePath = Environment.getExternalStorageDirectory() + File.separator + "OwlDatabase" + File.separator + "Profile.txt";
    private List<NavTab_C> navTabCList = new ArrayList<NavTab_C>();
    private List<Classity_C> classityCList = new ArrayList<Classity_C>();
    private List<Recommend_C> recommendCList = new ArrayList<Recommend_C>();
    private List<CustomizeToday_C> customizeTodayCList = new ArrayList<CustomizeToday_C>();
    private List<CustomizeDomestic_C> customizeCList = new ArrayList<CustomizeDomestic_C>();
    private List<CustomizeEA_C> customizeEACList = new ArrayList<CustomizeEA_C>();
    private BGABanner mDepthBanner;
    private NoScrollGridView lv_search, lv_classity;

    private static final int WHAT_LOADING = 0;

    private String CUSTOMIZE_DOMESTIC = "国产";
    private String CUSTOMIZE_JK = "日韩";
    private String CUSTOMIZE_CHINESE = "中文字幕";
    private String CUSTOMIZE_EA = "欧美";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_unnav_data);

        //状态栏颜色
        SystemUtil.setStatusBarColor(this, Color.parseColor("#448aca"));

        collectionstationGridview = (GridView) findViewById(R.id.gv_collectionstation);
        CustomizeGridview = (GridView) findViewById(R.id.gv_customize);
        gv_customizetoday = (GridView) findViewById(R.id.gv_customizetoday);
        gv_customizeea = (GridView) findViewById(R.id.gv_customizeea);

        hl_navtab = (HorizontalListView) findViewById(R.id.hl_navtab);
        lv_classity = (NoScrollGridView) findViewById(R.id.lv_classity);
        lv_search = (NoScrollGridView) findViewById(R.id.lv_search);
        tv_customize = (TextView) findViewById(R.id.tv_customize);
        tv_unnum = (TextView) findViewById(R.id.tv_unnum);
        tv_customize2 = (TextView) findViewById(R.id.tv_customize2);
        tv_search = (TextView) findViewById(R.id.tv_search);
        iv_billboard = (NetworkImageView) findViewById(R.id.iv_billboard);
        iv_billboard2 = (NetworkImageView) findViewById(R.id.iv_billboard2);

        iv_back = (ImageView) findViewById(R.id.iv_back);
        tv_changebatch = (TextView) findViewById(R.id.tv_changebatch);
        tv_warn = (TextView) findViewById(R.id.tv_warn);
        tv_warn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                tv_warn.setVisibility(View.GONE);
            }
        });

        initControl();

        //加载标题栏
        //LoadToolbar();

        // init_tab();
        //SD_Getnavaddress();

        //初始化轮播图
        initCarousel();


        String ConfigFiles_json = FileoOperations.readAssetsTxt(NavDataActivity.this, "TxtData/ConfigFiles");
        JSONObject objsd = JSONObject.parseObject(ConfigFiles_json);
        String ciphertext = objsd.getString("ADDRESSCIPHER");//地址密文
        String DecryptionAddress = Decrypt.RsaDecrypt(NavDataActivity.this, ciphertext);
        String typeseek = objsd.getString("TYPESEEK");//类型检索
        String todayupdate = objsd.getString("UNTODAYUPDATE");//今日更新
        String tabnav = objsd.getString("UNTABNAV");//导航

        //顶部导航
        init_tabnav(DecryptionAddress + tabnav);
        //页内导航
        init_classitylist(DecryptionAddress + tabnav);
        //国产
        init_CustomizeDomestic(DecryptionAddress + typeseek + CUSTOMIZE_DOMESTIC);
        //这是原来的推荐，接口改为视图后，接口不可用就改为日韩
        init_Recommend(DecryptionAddress + typeseek + CUSTOMIZE_JK);
        //欧美
        init_CustomizeEA(DecryptionAddress + typeseek + CUSTOMIZE_EA);
        //今日更新
        init_CustomizeToday(DecryptionAddress + todayupdate);


//        String ProfileStr = FileoOperations.readFromSDFile(this, ProfilePath);
//        //读取配置文件信息
//        try {
//            JSONObject obj = JSONObject.parseObject(ProfileStr);
//            String result3 = obj.getString("UN自定义类型接口");
//            String result = obj.getString("UN自定义类型名称2");
//            String ciphertext = obj.getString("地址密文");
//            String res = Decrypt.RsaDecrypt(NavDataActivity.this,ciphertext);
//            init_Recommend(res+result3+result);// + "?count=6"
//            String result2 = obj.getString("UN最近更新");
//
//
//            //UN自定义类型
//
//            String result4 = obj.getString("UN自定义类型名称");
//            tv_customize.setText(result4);
//            tv_customize2.setText(result);
//            init_Customize(res+result3+result4);
//
//
//        } catch (Exception e) {
//
//            Toast.makeText(NavDataActivity.this, "视频推荐地址错误", Toast.LENGTH_SHORT).show();
////异常处理
//        }


        billboard();
        //  loadingDialog();
        // tvwarnGone();

    }


    //等待刷新函数
    private void tvwarnGone() {
        //Toast.makeText(PlayerActivity.this, "编辑成功", Toast.LENGTH_SHORT).show();
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                //finish();
                //AnimationUtils.showAndHiddenAnimation(tv_skip, AnimationUtils.AnimationState.STATE_HIDDEN,2000);
                tv_warn.setVisibility(View.GONE);
            }
        }, 10000);
        // onCreate(null);//调用此方法刷新页面

    }
//****************************************************************************************************************************

    private void initControl() {
        tv_unnum.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                HttpResponse("http://103.45.145.67/AndroidApp/statistics/carnum.php");
            }
        });


        tv_search.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                //公开搜索
                intent.setClass(NavDataActivity.this, SearchActivity.class);
                startActivity(intent);
            }
        });
        iv_billboard.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                String BillBoard_B = FileoOperations.readAssetsTxt(NavDataActivity.this, "TxtData/BillBoard");
                JSONObject objsd = JSONObject.parseObject(BillBoard_B);
                String result = objsd.getString("UN广告标题1");
                String result2 = objsd.getString("UN广告地址1");
                advert(result, result2);


            }
        });

        iv_billboard2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                String BillBoard_B = FileoOperations.readAssetsTxt(NavDataActivity.this, "TxtData/BillBoard");
                JSONObject objsd = JSONObject.parseObject(BillBoard_B);
                String result = objsd.getString("UN广告标题2");
                String result2 = objsd.getString("UN广告地址2");
                advert(result, result2);
            }
        });
        iv_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        tv_changebatch.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {


                String ConfigFiles_json = FileoOperations.readAssetsTxt(NavDataActivity.this, "TxtData/ConfigFiles");
                JSONObject objsd = JSONObject.parseObject(ConfigFiles_json);
                String ciphertext = objsd.getString("ADDRESSCIPHER");//地址密文
                String DecryptionAddress = Decrypt.RsaDecrypt(NavDataActivity.this, ciphertext);
                String typeseek = objsd.getString("TYPESEEK");//类型检索

                //这是原来的推荐，接口改为视图后，接口不可用就改为日韩
                init_Recommend(DecryptionAddress + typeseek + CUSTOMIZE_JK);

            }
//
//            String ProfileStr = FileoOperations.readFromSDFile(NavDataActivity.this, ProfilePath);
//
//            //读取配置文件信息
//            try {
//                JSONObject obj = JSONObject.parseObject(ProfileStr);
//                // String result = obj.getString("UN视频推荐");
//                String result2 = obj.getString("地址密文");
//                String res = Decrypt.RsaDecrypt(NavDataActivity.this,result2);
//                //解密
//                // if(checkUrl(res+result,400)){
//                String result3 = obj.getString("UN自定义类型接口");
//                String result = obj.getString("UN自定义类型名称2");
//                init_Recommend(res+result3+result );//+ "?count=6"
//                // }else Log.i("response===========>", res+result);
//            } catch (Exception e) {
//
//                Toast.makeText(NavDataActivity.this, "视频推荐地址错误", Toast.LENGTH_SHORT).show();
////异常处理
//            }
//
//        }
        });
    }


    private void HttpResponse(String url) {


        OkHttpClient client = new OkHttpClient();
        Request request = new Request
                .Builder()
                .url(url)//要访问的链接
                .build();

        Call call = client.newCall(request);
        call.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {

            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                String res = response.body().string();
                //Log.i("response===========>",res);
                Message msg = new Message();
                msg.what = 40;
                Bundle bundle = new Bundle();
                bundle.putString("res", res);  //往Bundle中存放数据
                msg.setData(bundle);//mes利用Bundle传递数据
                Thandler.sendMessage(msg);//用activity中的handler发送消息

            }
        });

    }


    public void loadingDialog() {
        tDialog = new TDialog.Builder(getSupportFragmentManager())
                .setLayoutRes(R.layout.tdialog_loading)
                .setHeight(300)
                .setWidth(300)
                .setCancelableOutside(false)
                .create()
                .show();
        Thandler.sendEmptyMessageDelayed(WHAT_LOADING, 3 * 1000);

    }


    private void advert(String vod_name, String vod_play_url) {

        String res[] = vod_play_url.split("\\$");
        if (res[0].equals("player")) {
            //String res[] = result2.split("$");

            Intent intent = new Intent();
            Bundle bundle = new Bundle();
            bundle.putString("vod_name", vod_name);
            bundle.putString("vod_play_url", res[1]);
            intent.putExtras(bundle);
            intent.setClass(NavDataActivity.this, FullScreenActivity.class);
            startActivity(intent);

        }
        if (res[0].equals("search")) {

            try {
                //刷新
                Intent intent = new Intent();
                Bundle bundle = new Bundle();
                bundle.putString("SearchData", res[1]);
                intent.putExtras(bundle);
                intent.setClass(NavDataActivity.this, SearchListActivity.class);
                startActivity(intent);

            } catch (Exception e) {

                Toast.makeText(NavDataActivity.this, "配置文件错误", Toast.LENGTH_SHORT).show();
//异常处理
            }
        }
    }

    private void billboard() {
        String BillBoard_B = FileoOperations.readAssetsTxt(NavDataActivity.this, "TxtData/BillBoard");
        JSONObject objsd = JSONObject.parseObject(BillBoard_B);
        String result = objsd.getString("UN广告图片1");
        String result2 = objsd.getString("UN广告图片2");
        iv_billboard.setImageURL(result);
        iv_billboard2.setImageURL(result2);

    }

    private void initCarousel() {
        // https://github.com/wenchaosong/Banner  Android 图片轮播控件
        mDepthBanner = (BGABanner) findViewById(R.id.banner_main_depth);
        mDepthBanner.setAdapter(new BGABanner.Adapter<ImageView, String>() {
            @Override
            public void fillBannerItem(BGABanner banner, ImageView itemView, String model, int position) {
                Glide.with(NavDataActivity.this)
                        .load(model)
                        .placeholder(R.drawable.ic_image)
                        .error(R.drawable.ic_image)
                        .centerCrop()
                        .dontAnimate()
                        .into(itemView);
            }
        });
        //获取广告文件
        String BillBoard_B = FileoOperations.readAssetsTxt(NavDataActivity.this, "TxtData/BillBoard");
        JSONObject objsd = JSONObject.parseObject(BillBoard_B);
        String c1 = objsd.getString("UN轮播图片1");
        String c2 = objsd.getString("UN轮播图片2");
        String c3 = objsd.getString("UN轮播图片3");
        String c4 = objsd.getString("UN轮播图片4");

        String ct1 = objsd.getString("UN轮播标题1");
        String ct2 = objsd.getString("UN轮播标题2");
        String ct3 = objsd.getString("UN轮播标题3");
        String ct4 = objsd.getString("UN轮播标题4");
        mDepthBanner.setData(Arrays.asList(c1, c2, c3, c4), Arrays.asList(ct1, ct2, ct3, ct4));
        mDepthBanner.setDelegate(new BGABanner.Delegate<ImageView, String>() {
            @Override
            public void onBannerItemClick(BGABanner banner, ImageView itemView, String model, int position) {
                //Toast.makeText(banner.getContext(), "点击了" + model, Toast.LENGTH_SHORT).show();

                //根据图片地址查询数据库
                String BillBoard_B = FileoOperations.readAssetsTxt(NavDataActivity.this, "TxtData/BillBoard");
                JSONObject objsd = JSONObject.parseObject(BillBoard_B);
                String ct1 = objsd.getString("UN轮播标题1");
                String ct2 = objsd.getString("UN轮播标题2");
                String ct3 = objsd.getString("UN轮播标题3");
                String ct4 = objsd.getString("UN轮播标题4");
                if (position == 0) {
                    advert(ct1, "search$" + ct1);
                }
                if (position == 1) {
                    advert(ct2, "search$" + ct2);
                }
                if (position == 2) {
                    advert(ct3, "search$" + ct3);
                }
                if (position == 3) {
                    advert(ct4, "search$" + ct4);
                }


            }
        });
    }

    public static Boolean checkUrl(String address, int waitMilliSecond) {
        try {
            URL url = new URL(address);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setUseCaches(false);
            conn.setInstanceFollowRedirects(true);
            conn.setConnectTimeout(waitMilliSecond);
            conn.setReadTimeout(waitMilliSecond);

            //HTTP connect
            try {
                conn.connect();
            } catch (Exception e) {
                e.printStackTrace();
                return false;
            }

            int code = conn.getResponseCode();
            if ((code >= 100) && (code < 400)) {
                return true;
            }

            return false;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    private String SD_Getnavaddress() {

        Fromfileurl = (TextView) findViewById(R.id.fromfileurl);
        //读取sd文件的json
        String ProfileStr = FileoOperations.readFromSDFile(this, ProfilePath);
        //读取配置文件信息
        try {
            JSONObject obj = JSONObject.parseObject(ProfileStr);
            String result = obj.getString("UN分类导航");
            String ciphertext = obj.getString("地址密文");
            String res = Decrypt.RsaDecrypt(NavDataActivity.this, ciphertext);
            //Fromfileurl.setText(res+result);

            return res + result;

        } catch (Exception e) {

            Toast.makeText(NavDataActivity.this, "配置文件错误", Toast.LENGTH_SHORT).show();
//异常处理
        }
        return null;
    }

    //
//    private void LoadToolbar(){
//        Toolbar = (Toolbar)findViewById(R.id.toolbar);
//        setSupportActionBar(Toolbar);//利用Toolbar代替ActionBar
////        Toolbar.inflateMenu(R.menu.menu_user);
//        //设置的点击事件
//        Toolbar.setNavigationOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                //跳转到用户设置页面
//                finish();
//            }
//        });
////        //添加menu 菜单点击事件
////        Toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
////            @Override
////            public boolean onMenuItemClick(MenuItem item) {
////                switch (item.getItemId()){
////                    case R.id.action_save:
////                        finish();
////                        break;
////
////                }
////                return true;
////            }
////        });
//    }
    private void init_tab() {

        Message msg = new Message();
        msg.what = 12;
        Thandler.sendMessage(msg);//用activity中的handler发送消息
    }


    private Handler Thandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {


                case 12:
                    if (SD_Getnavaddress() != null) {
                        // get_classlist(SD_Getnavaddress());
                        //get_classitylist(SD_Getnavaddress());

                    } else Log.d("Thandler--12", "地址错误======" + SD_Getnavaddress());
                    break;
                case 16:
                    clickData((ArrayList<NavTab_C>) navTabCList);
                    break;
                case 18:

                    listClickListener((ArrayList<Recommend_C>) recommendCList);
                    break;

                case 22:

                    CustomizeVideoData((ArrayList<CustomizeDomestic_C>) customizeCList);
                    break;

                case 24:
                    classityClickData((ArrayList<Classity_C>) classityCList);
                    break;

                case 26:
                    CustomizeEAData((ArrayList<CustomizeEA_C>) customizeEACList);
                    break;
                case 40:
                    String res = msg.getData().getString("res").trim();
                    tv_unnum.setText(res);
                    break;
                case WHAT_LOADING:
                    if (tDialog != null) {
                        tDialog.dismiss();
                    }
                    return;

            }
        }
    };


    private NavTab_C navTab_c;

    public void init_tabnav(String Surl_file) {

        navTabCList.clear();

        OkHttpClient mOkHttpClient = new OkHttpClient();
        Request.Builder requestBuilder = new Request.Builder().url(Surl_file);
        //可以省略，默认是GET请求
        requestBuilder.method("GET", null);
        Request request = requestBuilder.build();
        Call mcall = mOkHttpClient.newCall(request);
        mcall.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                Log.d("1111", "onFailure: ");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                String jsoninfo = response.body().string();


                //String jsonstr3 = jsonstr2.replace("$$$在线播放$", "|");


                ByteArrayInputStream stream = new ByteArrayInputStream(jsoninfo.getBytes());
                StringBuffer stringBuffer = new StringBuffer();
                String str = null;
                BufferedReader br = new BufferedReader(new InputStreamReader(stream));
                while ((str = br.readLine()) != null) {
                    stringBuffer.append(str);
                }
                //03.使用fastJson解析Json、
                List<NavTab_C> subc = JSON.parseArray(stringBuffer.toString(), NavTab_C.class);
                for (NavTab_C pp : subc) {
                    navTab_c = new NavTab_C();
                    String count = pp.getCount();
                    String vod_class = pp.getVod_class();

                    // Log.d("ImageviewHolder", "显示图片url======" + vod_class);

                    navTab_c.setCount(count);
                    navTab_c.setVod_class(vod_class);

                    //pfilmclass.setParea(carea);
                    //将结果添加到对象集合中
                    navTabCList.add(navTab_c);
                }

                Message msg = new Message();
                msg.what = 16;
                Thandler.sendMessage(msg);//用activity中的handler发送消息
            }
        });

    }


    private Classity_C classityC;

    public void init_classitylist(String Surl_file) {

        classityCList.clear();

        OkHttpClient mOkHttpClient = new OkHttpClient();
        Request.Builder requestBuilder = new Request.Builder().url(Surl_file);
        //可以省略，默认是GET请求
        requestBuilder.method("GET", null);
        Request request = requestBuilder.build();
        Call mcall = mOkHttpClient.newCall(request);
        mcall.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                Log.d("1111", "onFailure: ");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                String jsoninfo = response.body().string();


                //String jsonstr3 = jsonstr2.replace("$$$在线播放$", "|");


                ByteArrayInputStream stream = new ByteArrayInputStream(jsoninfo.getBytes());
                StringBuffer stringBuffer = new StringBuffer();
                String str = null;
                BufferedReader br = new BufferedReader(new InputStreamReader(stream));
                while ((str = br.readLine()) != null) {
                    stringBuffer.append(str);
                }
                //03.使用fastJson解析Json、
                List<Classity_C> subc = JSON.parseArray(stringBuffer.toString(), Classity_C.class);
                for (Classity_C pp : subc) {
                    classityC = new Classity_C();
                    String count = pp.getCount();
                    String vod_class = pp.getVod_class();

                    // Log.d("ImageviewHolder", "显示图片url======" + vod_class);

                    classityC.setCount(count);
                    classityC.setVod_class(vod_class);

                    //pfilmclass.setParea(carea);
                    //将结果添加到对象集合中
                    classityCList.add(classityC);
                }

                Message msg = new Message();
                msg.what = 24;
                Thandler.sendMessage(msg);//用activity中的handler发送消息
            }
        });

    }


    private Classity_A classityA;

    public void classityClickData(ArrayList<Classity_C> classityCArrayList) {

        classityA = new Classity_A(R.layout.nav_classity_item, NavDataActivity.this, classityCArrayList);


        lv_classity.setAdapter(classityA);
        lv_classity.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                //Toast.makeText(getContext(), "Click item" + i, Toast.LENGTH_SHORT).show();
                final TextView vod_class = (TextView) view.findViewById(R.id.vod_class);//名称
                final TextView count = (TextView) view.findViewById(R.id.count);//数量

                String vod_class1 = vod_class.getText().toString();
                String count1 = count.getText().toString();

                Intent intent = new Intent();
                Bundle bundle = new Bundle();
                bundle.putString("vod_class1", vod_class1);
                bundle.putString("count1", count1);
                intent.putExtras(bundle);
                intent.setClass(NavDataActivity.this, cc.booku.owlbox.UnLayPage.LayPageActivity.class);
                startActivity(intent);

                // Log.i("test======", "===gather_name1===" + vod_class1 + "===gather_url1===" + count1);


            }
        });


    }


    private NavTab_A navTabA;

    public void clickData(ArrayList<NavTab_C> navTabCArrayList) {

        navTabA = new NavTab_A(R.layout.navtab_item, NavDataActivity.this, navTabCArrayList);


        hl_navtab.setAdapter(navTabA);
        hl_navtab.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                //Toast.makeText(getContext(), "Click item" + i, Toast.LENGTH_SHORT).show();
                final TextView vod_class = (TextView) view.findViewById(R.id.vod_class);//名称
                final TextView count = (TextView) view.findViewById(R.id.count);//数量

                String vod_class1 = vod_class.getText().toString();
                String count1 = count.getText().toString();

                Intent intent = new Intent();
                Bundle bundle = new Bundle();
                bundle.putString("vod_class1", vod_class1);
                bundle.putString("count1", count1);
                intent.putExtras(bundle);
                intent.setClass(NavDataActivity.this, cc.booku.owlbox.UnLayPage.LayPageActivity.class);
                startActivity(intent);

                // Log.i("test======", "===gather_name1===" + vod_class1 + "===gather_url1===" + count1);


            }
        });


    }

    //***************************************************************************************************推荐，已经改成日韩
    private Recommend_C recommendC;

    private void init_Recommend(String url) {

        recommendCList.clear();

        OkHttpClient client = new OkHttpClient();
        Request request = new Request
                .Builder()
                .url(url)//要访问的链接
                .build();

        Call call = client.newCall(request);
        call.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {

            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                String res = response.body().string();

                // String jsonstr1 = res.replace("[{", "{");
                // String jsonstr2 = jsonstr1.replace("}]", "}");


//                Message msg = new Message();
//                msg.what = 16;
//                Bundle bundle = new Bundle();
//                bundle.putString("jsondata",res);  //往Bundle中存放数据
//                // bundle.putString("text2","Time：2016-11-03");  //往Bundle中put数据
//                msg.setData(bundle);//mes利用Bundle传递数据
//                handler.sendMessage(msg);//用activity中的handler发送消息

                try {
                    List<Recommend_C> collectionStationCList = JSON.parseArray(res, Recommend_C.class);
                    for (Recommend_C normVideo : collectionStationCList) {
                        recommendC = new Recommend_C();

//    vod_score  ---评分
//    vod_name	----影片名称
//    vod_class  ----类型
//    vod_pic ----图片地址
//    vod_play_url --视频地址
//    vod_add_time  ---添加日期

//    vod_actor ---演员
//    vod_director ---导演
//    vod_blurb  ---影片简介
//    vod_area  ---地区
//    vod_year  ---上映年份
//    vod_lang  ---语言

                        String vod_score = normVideo.getVod_score();
                        String vod_name = normVideo.getVod_name();
                        String vod_class = normVideo.getVod_class();
                        String vod_add_time = normVideo.getVod_add_time();
                        String vod_pic = normVideo.getVod_pic();
                        String vod_play_url = normVideo.getVod_play_url();

                        String vod_actor = normVideo.getVod_actor();
                        String vod_director = normVideo.getVod_director();
                        String vod_blurb = normVideo.getVod_blurb();
                        String vod_area = normVideo.getVod_area();
                        String vod_year = normVideo.getVod_year();
                        String vod_lang = normVideo.getVod_lang();
                        String vod_id = normVideo.getVod_id();

                        // Log.d("ImageviewHolder", "显示图片url======" + vod_pic);

                        recommendC.setVod_score("评分:" + vod_score);
                        recommendC.setVod_name(vod_name);
                        recommendC.setVod_class(vod_class + "#" + vod_year + "#" + vod_area + "#" + vod_lang + "#" + vod_id);
                        recommendC.setVod_add_time(vod_add_time);
                        recommendC.setVod_pic(vod_pic);
                        recommendC.setVod_pic_url(vod_pic);
                        recommendC.setVod_play_url(vod_play_url);
                        recommendC.setVod_value_add("导演：" + vod_director + "\n演员：" + vod_actor + "\n类型：" + vod_class + "\n上映地区：" + vod_area + "\n上映年份：" + vod_year + "\n语言：" + vod_lang + "\n$片名：" + vod_name + "\n剧情简介：" + vod_blurb);


                        recommendCList.add(recommendC);
                    }

                } catch (Exception e) {

                    Log.i("onResponse===========>", res);
//异常处理
                }


                Message msg = new Message();
                msg.what = 18;
                Thandler.sendMessage(msg);//用activity中的handler发送消息
            }
        });

    }


    private Recommend_A recommendA;

    public void listClickListener(ArrayList<Recommend_C> recommendCS) {


        recommendA = new Recommend_A(R.layout.uncustomize_item, this, recommendCS);

        collectionstationGridview.setAdapter(recommendA);
        collectionstationGridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

                //Toast.makeText(getContext(), "Click ++ item" + i, Toast.LENGTH_SHORT).show();
                final TextView vod_class1 = (TextView) view.findViewById(R.id.vod_class);
                final TextView vod_score1 = (TextView) view.findViewById(R.id.vod_score);
                final TextView vod_name1 = (TextView) view.findViewById(R.id.vod_name);
                final TextView vod_add_time1 = (TextView) view.findViewById(R.id.vod_add_time);
                final TextView vod_play_url1 = (TextView) view.findViewById(R.id.vod_play_url);
                final TextView vod_value_add1 = (TextView) view.findViewById(R.id.vod_value_add);
                final TextView vod_pic_url1 = (TextView) view.findViewById(R.id.vod_pic_url);

                String vod_class2 = vod_class1.getText().toString();
                String vod_score2 = vod_score1.getText().toString();
                String vod_name2 = vod_name1.getText().toString();
                String vod_add_time2 = vod_add_time1.getText().toString();
                String vod_play_url2 = vod_play_url1.getText().toString();
                String vod_value_add2 = vod_value_add1.getText().toString();
                String vod_pic_url2 = vod_pic_url1.getText().toString();

                Intent intent = new Intent();
                Bundle bundle = new Bundle();
                bundle.putString("vod_class", vod_class2);
                bundle.putString("vod_score", vod_score2);
                bundle.putString("vod_name", vod_name2);
                bundle.putString("vod_add_time", vod_add_time2);
                bundle.putString("vod_play_url", vod_play_url2);
                bundle.putString("vod_value_add", vod_value_add2);
                bundle.putString("vod_pic", vod_pic_url2);
                intent.putExtras(bundle);
                intent.setClass(NavDataActivity.this, PlayerActivity.class);
                startActivity(intent);


            }
        });

    }

    //*************************************************************************************************************欧美
    private CustomizeEA_C customizeEAC;

    private void init_CustomizeEA(String url) {

        customizeCList.clear();

        OkHttpClient client = new OkHttpClient();
        Request request = new Request
                .Builder()
                .url(url)//要访问的链接
                .build();

        Call call = client.newCall(request);
        call.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {

            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                String res = response.body().string();

//                String jsonstr1 = res.replace("[{", "{");
//                String jsonstr2 = jsonstr1.replace("}]", "}");


//                Message msg = new Message();
//                msg.what = 16;
//                Bundle bundle = new Bundle();
//                bundle.putString("jsondata",res);  //往Bundle中存放数据
//                // bundle.putString("text2","Time：2016-11-03");  //往Bundle中put数据
//                msg.setData(bundle);//mes利用Bundle传递数据
//                handler.sendMessage(msg);//用activity中的handler发送消息

                try {
                    List<CustomizeEA_C> collectionStationCList = JSON.parseArray(res, CustomizeEA_C.class);
                    for (CustomizeEA_C normVideo : collectionStationCList) {
                        customizeEAC = new CustomizeEA_C();

//    vod_score  ---评分
//    vod_name	----影片名称
//    vod_class  ----类型
//    vod_pic ----图片地址
//    vod_play_url --视频地址
//    vod_add_time  ---添加日期

//    vod_actor ---演员
//    vod_director ---导演
//    vod_blurb  ---影片简介
//    vod_area  ---地区
//    vod_year  ---上映年份
//    vod_lang  ---语言

                        String vod_score = normVideo.getVod_score();
                        String vod_name = normVideo.getVod_name();
                        String vod_class = normVideo.getVod_class();
                        String vod_add_time = normVideo.getVod_add_time();
                        String vod_pic = normVideo.getVod_pic();
                        String vod_play_url = normVideo.getVod_play_url();

                        String vod_actor = normVideo.getVod_actor();
                        String vod_director = normVideo.getVod_director();
                        String vod_blurb = normVideo.getVod_blurb();
                        String vod_area = normVideo.getVod_area();
                        String vod_year = normVideo.getVod_year();
                        String vod_lang = normVideo.getVod_lang();
                        String vod_id = normVideo.getVod_id();

                        // Log.d("ImageviewHolder", "显示图片url======" + vod_pic);

                        customizeEAC.setVod_score("评分:" + vod_score);
                        customizeEAC.setVod_name(vod_name);
                        customizeEAC.setVod_class(vod_class + "#" + vod_year + "#" + vod_area + "#" + vod_lang + "#" + vod_id);
                        customizeEAC.setVod_add_time(vod_add_time);
                        customizeEAC.setVod_pic(vod_pic);
                        customizeEAC.setVod_pic_url(vod_pic);
                        customizeEAC.setVod_play_url(vod_play_url);
                        customizeEAC.setVod_value_add("导演：" + vod_director + "\n演员：" + vod_actor + "\n类型：" + vod_class + "\n上映地区：" + vod_area + "\n上映年份：" + vod_year + "\n语言：" + vod_lang + "\n$片名：" + vod_name + "\n剧情简介：" + vod_blurb);


                        customizeEACList.add(customizeEAC);
                    }

                } catch (Exception e) {

                    Log.i("onResponse===========>", res);
//异常处理
                }


                Message msg = new Message();
                msg.what = 26;
                Thandler.sendMessage(msg);//用activity中的handler发送消息
            }
        });

    }

    private CustomizeEA_A customizeEAA;

    public void CustomizeEAData(ArrayList<CustomizeEA_C> customizeEACS) {


        customizeEAA = new CustomizeEA_A(R.layout.uncustomize_item, this, customizeEACS);

        gv_customizeea.setAdapter(customizeEAA);
        gv_customizeea.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

                //Toast.makeText(getContext(), "Click ++ item" + i, Toast.LENGTH_SHORT).show();
                final TextView vod_class1 = (TextView) view.findViewById(R.id.vod_class);
                final TextView vod_score1 = (TextView) view.findViewById(R.id.vod_score);
                final TextView vod_name1 = (TextView) view.findViewById(R.id.vod_name);
                final TextView vod_add_time1 = (TextView) view.findViewById(R.id.vod_add_time);
                final TextView vod_play_url1 = (TextView) view.findViewById(R.id.vod_play_url);
                final TextView vod_value_add1 = (TextView) view.findViewById(R.id.vod_value_add);
                final TextView vod_pic_url1 = (TextView) view.findViewById(R.id.vod_pic_url);

                String vod_class2 = vod_class1.getText().toString();
                String vod_score2 = vod_score1.getText().toString();
                String vod_name2 = vod_name1.getText().toString();
                String vod_add_time2 = vod_add_time1.getText().toString();
                String vod_play_url2 = vod_play_url1.getText().toString();
                String vod_value_add2 = vod_value_add1.getText().toString();
                String vod_pic_url2 = vod_pic_url1.getText().toString();

                Intent intent = new Intent();
                Bundle bundle = new Bundle();
                bundle.putString("vod_class", vod_class2);
                bundle.putString("vod_score", vod_score2);
                bundle.putString("vod_name", vod_name2);
                bundle.putString("vod_add_time", vod_add_time2);
                bundle.putString("vod_play_url", vod_play_url2);
                bundle.putString("vod_value_add", vod_value_add2);
                bundle.putString("vod_pic", vod_pic_url2);
                intent.putExtras(bundle);
                intent.setClass(NavDataActivity.this, PlayerActivity.class);
                startActivity(intent);


            }
        });

    }
//***********************************************************************************************************自定义国产

    private CustomizeDomestic_C customizeC;

    private void init_CustomizeDomestic(String url) {

        customizeCList.clear();

        OkHttpClient client = new OkHttpClient();
        Request request = new Request
                .Builder()
                .url(url)//要访问的链接
                .build();

        Call call = client.newCall(request);
        call.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {

            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                String res = response.body().string();

//                String jsonstr1 = res.replace("[{", "{");
//                String jsonstr2 = jsonstr1.replace("}]", "}");


//                Message msg = new Message();
//                msg.what = 16;
//                Bundle bundle = new Bundle();
//                bundle.putString("jsondata",res);  //往Bundle中存放数据
//                // bundle.putString("text2","Time：2016-11-03");  //往Bundle中put数据
//                msg.setData(bundle);//mes利用Bundle传递数据
//                handler.sendMessage(msg);//用activity中的handler发送消息

                try {
                    List<CustomizeDomestic_C> collectionStationCList = JSON.parseArray(res, CustomizeDomestic_C.class);
                    for (CustomizeDomestic_C normVideo : collectionStationCList) {
                        customizeC = new CustomizeDomestic_C();

//    vod_score  ---评分
//    vod_name	----影片名称
//    vod_class  ----类型
//    vod_pic ----图片地址
//    vod_play_url --视频地址
//    vod_add_time  ---添加日期

//    vod_actor ---演员
//    vod_director ---导演
//    vod_blurb  ---影片简介
//    vod_area  ---地区
//    vod_year  ---上映年份
//    vod_lang  ---语言

                        String vod_score = normVideo.getVod_score();
                        String vod_name = normVideo.getVod_name();
                        String vod_class = normVideo.getVod_class();
                        String vod_add_time = normVideo.getVod_add_time();
                        String vod_pic = normVideo.getVod_pic();
                        String vod_play_url = normVideo.getVod_play_url();

                        String vod_actor = normVideo.getVod_actor();
                        String vod_director = normVideo.getVod_director();
                        String vod_blurb = normVideo.getVod_blurb();
                        String vod_area = normVideo.getVod_area();
                        String vod_year = normVideo.getVod_year();
                        String vod_lang = normVideo.getVod_lang();
                        String vod_id = normVideo.getVod_id();

                        // Log.d("ImageviewHolder", "显示图片url======" + vod_pic);

                        customizeC.setVod_score("评分:" + vod_score);
                        customizeC.setVod_name(vod_name);
                        customizeC.setVod_class(vod_class + "#" + vod_year + "#" + vod_area + "#" + vod_lang + "#" + vod_id);
                        customizeC.setVod_add_time(vod_add_time);
                        customizeC.setVod_pic(vod_pic);
                        customizeC.setVod_pic_url(vod_pic);
                        customizeC.setVod_play_url(vod_play_url);
                        customizeC.setVod_value_add("导演：" + vod_director + "\n演员：" + vod_actor + "\n类型：" + vod_class + "\n上映地区：" + vod_area + "\n上映年份：" + vod_year + "\n语言：" + vod_lang + "\n$片名：" + vod_name + "\n剧情简介：" + vod_blurb);


                        customizeCList.add(customizeC);
                    }

                } catch (Exception e) {

                    Log.i("onResponse===========>", res);
//异常处理
                }


                Message msg = new Message();
                msg.what = 22;
                Thandler.sendMessage(msg);//用activity中的handler发送消息
            }
        });

    }

    private CustomizeDomestic_A customizeA;

    public void CustomizeVideoData(ArrayList<CustomizeDomestic_C> customizeCS) {


        customizeA = new CustomizeDomestic_A(R.layout.uncustomize_item, this, customizeCS);

        CustomizeGridview.setAdapter(customizeA);
        CustomizeGridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

                //Toast.makeText(getContext(), "Click ++ item" + i, Toast.LENGTH_SHORT).show();
                final TextView vod_class1 = (TextView) view.findViewById(R.id.vod_class);
                final TextView vod_score1 = (TextView) view.findViewById(R.id.vod_score);
                final TextView vod_name1 = (TextView) view.findViewById(R.id.vod_name);
                final TextView vod_add_time1 = (TextView) view.findViewById(R.id.vod_add_time);
                final TextView vod_play_url1 = (TextView) view.findViewById(R.id.vod_play_url);
                final TextView vod_value_add1 = (TextView) view.findViewById(R.id.vod_value_add);
                final TextView vod_pic_url1 = (TextView) view.findViewById(R.id.vod_pic_url);

                String vod_class2 = vod_class1.getText().toString();
                String vod_score2 = vod_score1.getText().toString();
                String vod_name2 = vod_name1.getText().toString();
                String vod_add_time2 = vod_add_time1.getText().toString();
                String vod_play_url2 = vod_play_url1.getText().toString();
                String vod_value_add2 = vod_value_add1.getText().toString();
                String vod_pic_url2 = vod_pic_url1.getText().toString();

                Intent intent = new Intent();
                Bundle bundle = new Bundle();
                bundle.putString("vod_class", vod_class2);
                bundle.putString("vod_score", vod_score2);
                bundle.putString("vod_name", vod_name2);
                bundle.putString("vod_add_time", vod_add_time2);
                bundle.putString("vod_play_url", vod_play_url2);
                bundle.putString("vod_value_add", vod_value_add2);
                bundle.putString("vod_pic", vod_pic_url2);
                intent.putExtras(bundle);
                intent.setClass(NavDataActivity.this, PlayerActivity.class);
                startActivity(intent);


            }
        });

    }

    //********************************************************************************************************************************今日更新************
    private CustomizeToday_C customizeTodayC;

    private void init_CustomizeToday(String url) {

        customizeTodayCList.clear();

        OkHttpClient client = new OkHttpClient();
        Request request = new Request
                .Builder()
                .url(url)//要访问的链接
                .build();

        Call call = client.newCall(request);
        call.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {

            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                String res = response.body().string();

//                String jsonstr1 = res.replace("[{", "{");
//                String jsonstr2 = jsonstr1.replace("}]", "}");


//                Message msg = new Message();
//                msg.what = 16;
//                Bundle bundle = new Bundle();
//                bundle.putString("jsondata",res);  //往Bundle中存放数据
//                // bundle.putString("text2","Time：2016-11-03");  //往Bundle中put数据
//                msg.setData(bundle);//mes利用Bundle传递数据
//                handler.sendMessage(msg);//用activity中的handler发送消息

                try {
                    List<CustomizeToday_C> collectionStationCList = JSON.parseArray(res, CustomizeToday_C.class);
                    for (CustomizeToday_C normVideo : collectionStationCList) {
                        customizeTodayC = new CustomizeToday_C();

//    vod_score  ---评分
//    vod_name	----影片名称
//    vod_class  ----类型
//    vod_pic ----图片地址
//    vod_play_url --视频地址
//    vod_add_time  ---添加日期

//    vod_actor ---演员
//    vod_director ---导演
//    vod_blurb  ---影片简介
//    vod_area  ---地区
//    vod_year  ---上映年份
//    vod_lang  ---语言

                        String vod_score = normVideo.getVod_score();
                        String vod_name = normVideo.getVod_name();
                        String vod_class = normVideo.getVod_class();
                        String vod_add_time = normVideo.getVod_add_time();
                        String vod_pic = normVideo.getVod_pic();
                        String vod_play_url = normVideo.getVod_play_url();

                        String vod_actor = normVideo.getVod_actor();
                        String vod_director = normVideo.getVod_director();
                        String vod_blurb = normVideo.getVod_blurb();
                        String vod_area = normVideo.getVod_area();
                        String vod_year = normVideo.getVod_year();
                        String vod_lang = normVideo.getVod_lang();
                        String vod_id = normVideo.getVod_id();

                        // Log.d("ImageviewHolder", "显示图片url======" + vod_pic);

                        customizeTodayC.setVod_score("评分:" + vod_score);
                        customizeTodayC.setVod_name(vod_name);
                        customizeTodayC.setVod_class(vod_class + "#" + vod_year + "#" + vod_area + "#" + vod_lang + "#" + vod_id);
                        customizeTodayC.setVod_add_time(vod_add_time);
                        customizeTodayC.setVod_pic(vod_pic);
                        customizeTodayC.setVod_pic_url(vod_pic);
                        customizeTodayC.setVod_play_url(vod_play_url);
                        customizeTodayC.setVod_value_add("导演：" + vod_director + "\n演员：" + vod_actor + "\n类型：" + vod_class + "\n上映地区：" + vod_area + "\n上映年份：" + vod_year + "\n语言：" + vod_lang + "\n$片名：" + vod_name + "\n剧情简介：" + vod_blurb);


                        customizeTodayCList.add(customizeTodayC);
                    }

                } catch (Exception e) {

                    Log.i("onResponse===========>", res);
//异常处理
                }


                Message msg = new Message();
                msg.what = 25;
                Thandler.sendMessage(msg);//用activity中的handler发送消息
            }
        });

    }

    private CustomizeToday_A customizeTodayA;

    private void CustomizeTodayData(ArrayList<CustomizeToday_C> customizeTodayCS) {


        customizeTodayA = new CustomizeToday_A(R.layout.uncustomize_item, this, customizeTodayCS);

        gv_customizetoday.setAdapter(customizeTodayA);
        gv_customizetoday.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

                //Toast.makeText(getContext(), "Click ++ item" + i, Toast.LENGTH_SHORT).show();
                final TextView vod_class1 = (TextView) view.findViewById(R.id.vod_class);
                final TextView vod_score1 = (TextView) view.findViewById(R.id.vod_score);
                final TextView vod_name1 = (TextView) view.findViewById(R.id.vod_name);
                final TextView vod_add_time1 = (TextView) view.findViewById(R.id.vod_add_time);
                final TextView vod_play_url1 = (TextView) view.findViewById(R.id.vod_play_url);
                final TextView vod_value_add1 = (TextView) view.findViewById(R.id.vod_value_add);
                final TextView vod_pic_url1 = (TextView) view.findViewById(R.id.vod_pic_url);

                String vod_class2 = vod_class1.getText().toString();
                String vod_score2 = vod_score1.getText().toString();
                String vod_name2 = vod_name1.getText().toString();
                String vod_add_time2 = vod_add_time1.getText().toString();
                String vod_play_url2 = vod_play_url1.getText().toString();
                String vod_value_add2 = vod_value_add1.getText().toString();
                String vod_pic_url2 = vod_pic_url1.getText().toString();

                Intent intent = new Intent();
                Bundle bundle = new Bundle();
                bundle.putString("vod_class", vod_class2);
                bundle.putString("vod_score", vod_score2);
                bundle.putString("vod_name", vod_name2);
                bundle.putString("vod_add_time", vod_add_time2);
                bundle.putString("vod_play_url", vod_play_url2);
                bundle.putString("vod_value_add", vod_value_add2);
                bundle.putString("vod_pic", vod_pic_url2);
                intent.putExtras(bundle);
                intent.setClass(NavDataActivity.this, VideoPlayerActivity.class);
                startActivity(intent);


            }
        });

    }


}
